package com.gpscookie.redpanic;

import android.graphics.Canvas;

public abstract class Entity {

	protected volatile float x=0;
	protected volatile float y=0;
	protected float width=0;
	protected float height=0;
	protected float speed = 0;
	protected boolean live = true;
	protected int radius = 5;	
	
	/**
	 * Detect if two entities collide, assuming rectangles
	 * @param other
	 * @return
	 */
	public boolean isOverlapped(Entity other) {
		return ((x<other.x+other.width)
				&&(y<other.y+other.height)
				&&(x+width>other.x)
				&&(y+height>other.y));
	}
	
	/**
	 * Move this entity one step forward along a path
	 */
	public void step() {
		// stationary by default
		x = x;
		y = y;
	}
	
	/**
	 * Check if this entity is out of the world boundry
	 * @return
	 */
	public boolean isOut() {
		return (x>World.INSTANCE.width || y>World.INSTANCE.height);
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

	public boolean isLive() {return live;}
	
	public abstract void explode();
	public abstract void draw(Canvas canvas);
}
